<?php
	session_start();
	/**
	* @package admin
	* @desc Page for viewing proposals submitted by one user from database.
	*/
	// Direct calling check
	if (!isset($_SESSION["role"]))
	{
		header('Location: ../index.php');
		exit();
	}
	if ($_SESSION["role"] != "admin")
	{
		header('Location: ../index.php');
		exit();
	}
	if(!isset($_GET['id']))
	{
		header('Location: proposals.php');
		exit();
	}
	
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	require '../includes/smarty.inc';
	$smarty->assign('title', "Add Park");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->assign('pathdepth', "../");
	$smarty->display('header.tpl');
	
	
	$id = $_GET['id'];
	
	//get proposal details from database
	$query = "SELECT p.proposal_id as prop, u.email as email, p.comment as comment, p.address as address, p.forwarded as forwarded, s.name as suburb, c.email as council FROM proposals p, users u, suburbs s, councils c WHERE p.proposal_id = $id AND (p.user_id = u.user_id) AND (p.suburb_id = s.suburb_id) AND (s.council_id = c.council_id)";
	
	/**
	* @desc This include file connects to the database.
	*/
	require '../includes/connect.inc';
	
	//run query
	$result = mysql_query($query, $connection) or die("Could not load park proposal from database");
	
	//disconnect from db
	mysql_close($connection);
	
	$row = mysql_fetch_array($result);
	$id = $row['prop'];
	$user = $row['email'];
	$prop = $row['comment'];
	$address = $row['address'];
	$suburb = $row['suburb'];
	$council = $row['council'];
	$forwarded = $row['forwarded'];
	
	
	$smarty->assign('id', $id);
	$smarty->assign('user', $user);
	$smarty->assign('prop', $prop);
	$smarty->assign('address', $address);
	$smarty->assign('suburb', $suburb);
	$smarty->assign('forwarded', $forwarded);
	$smarty->assign('council', $council);
	$smarty->assign('admin', $_SESSION['email']);
	
	$smarty->display('admin/proposal.tpl');
	
	
	
		$smarty->assign('pathdepth', "../");
	$smarty->display('footer.tpl');
	
?>